﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 共享单车管理系统.star
{
    public partial class changePwd : Form
    {
        public changePwd()
        {
            InitializeComponent();
        }

        private void buttonok_Click(object sender, EventArgs e)
        {
            if(txtoldpwd.Text=="")
            {
                MessageBox.Show("原密码不能为空");
            }
            else
            {
                DB.GetCn();
                string str = "select * from Employee where EmployeeID='" + txtname.Text
                    +"'and Password='" + txtoldpwd.Text + "'";
                DataTable dt = DB.GetDataSet(str);
                
                if(dt.Rows.Count<1)
                {
                    MessageBox.Show("原密码错误，重新输入");
                }
                else
                {
                    if (txtnewpwd.Text == "" || txtnewpwd2.Text == "")
                    {
                        MessageBox.Show("输入新密码");
                    }
                    else
                    {
                        if(txtnewpwd2.Text !=txtnewpwd.Text)
                        {
                            MessageBox.Show("俩次密码不一致，重新输入");
                        }
                        else
                        {
                            string sdr = "update Employee set Password='"
                                + txtnewpwd.Text + "'where EmployeeID='" + txtname.Text.Trim() + "'";
                            DB.sqlEx(sdr);
                            MessageBox.Show("修改成功");
                            this.Close();
                        }
                    }
                   
                }
               
            }
        }

        private void changePwd_Load(object sender, EventArgs e)
        {
            txtname.Text = Login.EmployeeID;
        }

        private void txtoldpwd_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtname_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
